package com.ruoyi.web.controller.devices;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserPool;
import com.ruoyi.system.service.IUserPoolService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * poolController
 * 
 * @author ruoyi
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/system/pool")
public class UserPoolController extends BaseController
{
    @Autowired
    private IUserPoolService userPoolService;

    /**
     * 查询pool列表
     */
    @PreAuthorize("@ss.hasPermi('system:pool:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPool userPool)
    {
        startPage();
        List<UserPool> list = userPoolService.selectUserPoolList(userPool);
        return getDataTable(list);
    }

    /**
     * 导出pool列表
     */
    @PreAuthorize("@ss.hasPermi('system:pool:export')")
    @Log(title = "pool", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPool userPool)
    {
        List<UserPool> list = userPoolService.selectUserPoolList(userPool);
        ExcelUtil<UserPool> util = new ExcelUtil<UserPool>(UserPool.class);
        util.exportExcel(response, list, "pool数据");
    }

    /**
     * 获取pool详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pool:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(userPoolService.selectUserPoolByUserId(userId));
    }

    /**
     * 新增pool
     */
    @PreAuthorize("@ss.hasPermi('system:pool:add')")
    @Log(title = "pool", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPool userPool)
    {
        return toAjax(userPoolService.insertUserPool(userPool));
    }

    /**
     * 修改pool
     */
    @PreAuthorize("@ss.hasPermi('system:pool:edit')")
    @Log(title = "pool", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPool userPool)
    {
        return toAjax(userPoolService.updateUserPool(userPool));
    }

    /**
     * 删除pool
     */
    @PreAuthorize("@ss.hasPermi('system:pool:remove')")
    @Log(title = "pool", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(userPoolService.deleteUserPoolByUserIds(userIds));
    }
}
